package com.gao.handler;

import com.gao.manager.jwt.JwtKeeper;
import com.gao.util.WebUtils;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author gao
 * @time 2022/11/10 21:23:06
 */
@Component
@RequiredArgsConstructor
public class JsonLogoutSuccessHandlerImpl implements LogoutSuccessHandler {

    @NonNull
    private JwtKeeper jwtKeeper;

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        String json = WebUtils.generateSuccessJson("登出成功!");
        WebUtils.renderString(response, json);
    }
}
